package com.yugao.fintech.antelope.system.manager;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yugao.fintech.antelope.system.mapper.RamModuleMapper;
import com.yugao.fintech.antelope.system.model.entity.RamModule;
import com.yugao.fintech.framework.assistant.utils.CollectionUtils;
import com.yugao.fintech.framework.core.annotations.FieldUniqueCheck;
import com.yugao.fintech.framework.core.enums.OperationTypeEnum;
import org.springframework.stereotype.Service;

import java.util.Collection;
import java.util.Collections;
import java.util.List;


@Service
public class RamModuleManager extends ServiceImpl<RamModuleMapper, RamModule> {

    @FieldUniqueCheck(type = OperationTypeEnum.UPDATE)
    public boolean updateModuleById(RamModule entity) {
        return this.updateById(entity);
    }

    public RamModule getModuleByCode(String moduleCode) {
        LambdaQueryWrapper<RamModule> lqw = RamModule.lqw().eq(RamModule::getCode, moduleCode);
        return this.getOne(lqw);
    }

    public List<RamModule> listModuleByCodes(Collection<String> codes) {
        if (CollectionUtils.isEmpty(codes)) {
            return Collections.emptyList();
        }
        return this.list(RamModule.lqw().in(RamModule::getCode, codes));
    }
}
